import {userAuthStore} from "@/store/auth.js";

const hasPermission = (permission) => {
    const store = userAuthStore();
    const {permissions} = store

    if (permissions && permissions.length > 0) {
        return permissions.includes(permission)
    }
    return permission
}

function checkPermission(el, binding) {
    if (!hasPermission(binding.value)) {
        el.parentNode && el.parentNode.removeChild(el)
    }
}

export const permission = {
    mounted(el, binding) {
        checkPermission(el, binding);
    },
    updated(el, binding) {
        checkPermission(el, binding);
    },
}